package lq3808;

import java.util.Scanner;

public class Main {
    static int[] a = new int[100010];
    static int[] s = new int[100010];

    public static void solve() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        for (int i = 1; i <= n; i++) {
            a[i] = sc.nextInt();
        }

        //前缀和预处理
        for (int i = 2; i < n; i++) {
            if (a[i] > a[i-1] && a[i] > a[i+1]) {
                s[i] = s[i-1] + 1;
            } else {
                s[i] = s[i-1];
            }
        }

        //处理全部查询
        int q = sc.nextInt();
        for (int i = 1; i <= q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            if (l == r) {
                System.out.println(0);
            } else {
                System.out.println(s[r-1] - s[l]);
            }
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int t = 1;
        for (int zu = 1; zu <= t; zu++) {
            solve();
        }
    }
}